package BookManagement.operation;

import BookManagement.book.Bookshelf;

import java.util.Scanner;

public class ReturnBook implements IBusinessOperation{
    @Override
    public void work(Bookshelf bookshelf) {
        System.out.println("归还图书……");
        System.out.println("请用户输入要归还的书籍名称：");
        String name = "";
        Scanner scan = new Scanner(System.in);
        name = scan.nextLine();
        int number = bookshelf.book_umber;
        //先查找用户借阅的书籍是否存在或者是否已经借出
        int i = 0;
        for(;i<number; i++){
            if(name.equals(bookshelf.books[i].getName()) && bookshelf.books[i].getStatus()){
                //书籍存在并且没被借出
                //此时修改书籍的借阅状态
                System.out.println("书籍已归还！");
                bookshelf.books[i].setStatus(false);
                System.out.println(bookshelf.books[i]);
                break;
            }
        }

    }
}
